package com.animations;

import com.beans.ReadyBean;
import creator.ui.graphics.Magicanvas;
import creator.ui.graphics.polaroid.Animation;
import java.awt.AlphaComposite;
import java.awt.Composite;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.io.PrintStream;
import java.util.ArrayList;

public class ReadyAction extends Animation {

  private ReadyBean ready;
  private Composite alpha = AlphaComposite.SrcOver.derive(1.0F);

  public void loadBean() {
    this.ready = new ReadyBean();
    getBeans().add(this.ready);
  }

  public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    g2d.setComposite(this.alpha);
    g2d.drawImage(
      this.ready.getReady(),
      this.ready.getReadyX(),
      this.ready.getReadyY(),
      getMagicanvas()
    );
  }

  public void run() {
    try {
      while (true) {
        System.out.println("-> Play : " + Tag._isPlay());
        if (Tag._isPlay()) {
          float i = 1.0F;
          while (true) {
            if (i < 0.0F) {
              i = 0.0F;
              this.alpha = AlphaComposite.SrcOver.derive(i);
              break;
            }
            this.alpha = AlphaComposite.SrcOver.derive(i);
            i -= 0.2F;

            Thread.sleep(30L);
            getMagicanvas().repaint();
          }
          Tag._setDisappear(true);
          break;
        }
        Thread.sleep(300L);
      }
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
  }
}
